package com.sino.dataworks.service.impl;

import com.sino.dataworks.entity.DwDutyRoster;
import com.sino.dataworks.repository.DwDutyRosterRepository;
import com.sino.dataworks.service.DwDutyRosterService;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
@author Tison
*/
@Service
public class DwDutyRosterServiceImpl  implements DwDutyRosterService  {

	@Resource
	private DwDutyRosterRepository rep;


	 public DwDutyRoster save(DwDutyRoster obj) {
		 return rep.save(obj);
	 }


	 @Transactional
	 public List<DwDutyRoster> saveAll(Iterable<DwDutyRoster> list) {
		 return rep.saveAll(list);
	 }


	 public DwDutyRoster getOne(String id) {
		 return rep.getOne(id);
	 }


	 public DwDutyRoster findById(String id) {
		 Optional<DwDutyRoster> obj = rep.findById(id);
		 return obj.isPresent()?obj.get():null;
	 }


	 public void deleteById(String id) {
		 rep.deleteById(id);
	 }


	 @Transactional
	 public void deleteAll(List list) {
		 rep.deleteAll(list);
	 }


	 public void delete(DwDutyRoster obj) {
		 rep.delete(obj);
	 }


	 public boolean existsById(String id) {
		 return rep.existsById(id);
	 }


	 public long count() {
		 return rep.count();
	 }


	 public List<DwDutyRoster> findAll() {
		 return rep.findAll();
	 }


	 public List<DwDutyRoster> findAll(DwDutyRoster obj) {
		 List<DwDutyRoster> list = rep.findAll(Example.of(obj));
		 return list==null||list.size()<1?null:list;
	 }


	 public List<DwDutyRoster> findAll(Sort sort) {
		 return rep.findAll(sort);
	 }


	 public List<DwDutyRoster> findAllById(Iterable<String> ids) {
		 return rep.findAllById(ids);
	 }


	 public List<DwDutyRoster> findAll(Example<DwDutyRoster> e) {
		 return rep.findAll(e);
	 }


	 public List<DwDutyRoster> findAll(Example<DwDutyRoster> e, Sort sort) {
		 return rep.findAll(e,sort);
	 }


	 public Page<DwDutyRoster> findAll(Pageable page) {
		 return rep.findAll(page);
	 }


	 public Page<DwDutyRoster> findAll(Example<DwDutyRoster> e, Pageable page) {
		 return rep.findAll(e,page);
	 }


	 public Page<DwDutyRoster> findAll(DwDutyRoster obj, Pageable page) {
		 return rep.findAll(Example.of(obj),page);
	 }


	@Override
	public List<DwDutyRoster> getAllPhone() {
		return rep.findAll();
	}

	@Override
	@Transactional
	public void save(List<DwDutyRoster> list) {
		for (DwDutyRoster d:list){
			rep.deleteByDataDt(d.getDataDt());
		}
		rep.saveAll(list);
	}
}
